﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
public partial class zoushitu_dlt_dlt_joyl : System.Web.UI.Page
{
    protected List<Model.LotteryAnnouncement> arlist = null;
    protected string[] SSQList = null;
    protected string SSQblue = null;
    protected DataTable dtPaperList = new DataTable();
    protected int jinqiCount = 0;
    protected Hashtable qqjs_dt = new Hashtable();//前区奇数
    protected Hashtable qqos_dt = new Hashtable();//前区偶数
    protected Hashtable hqjs_dt = new Hashtable();//后区奇数
    protected Hashtable hqos_dt = new Hashtable();//后区偶数

    protected Hashtable qqjs_tiao = new Hashtable();
    protected Hashtable qqos_tiao = new Hashtable();
    protected Hashtable hqjs_tiao = new Hashtable();
    protected Hashtable hqos_tiao = new Hashtable();
    protected int TiaoXing;

    protected void Page_Load(object sender, EventArgs e)
    {
        ZoushiManage.FangWenZouShi();
        if (!IsPostBack)
        {
            jinqiCount = 30;
            bindData(30);
            YiLouZhi1(30);
        }
    }

    protected void bindData(int maxValue)
    {
        arlist = BLL.LotteryAnnouncement.getDatas(maxValue, 2);
        if (arlist != null)
        {
            #region 列表初始化   
            qqjs_dt.Add(17, 35);
            qqjs_dt.Add(16, 33);
            qqjs_dt.Add(15, 31);
            qqjs_dt.Add(14, 29);
            qqjs_dt.Add(13, 27);
            qqjs_dt.Add(12, 25);
            qqjs_dt.Add(11, 23);
            qqjs_dt.Add(10, 21);
            qqjs_dt.Add(9, 19);
            qqjs_dt.Add(8, 17);
            qqjs_dt.Add(7, 15);
            qqjs_dt.Add(6, 13);
            qqjs_dt.Add(5, 11);
            qqjs_dt.Add(4, 09);
            qqjs_dt.Add(3, 07);
            qqjs_dt.Add(2, 05);
            qqjs_dt.Add(1, 03);
            qqjs_dt.Add(0, 01);




            qqos_dt.Add(34, 34);
            qqos_dt.Add(33, 32);
            qqos_dt.Add(32, 30);
            qqos_dt.Add(31, 28);
            qqos_dt.Add(30, 26);
            qqos_dt.Add(29, 24);
            qqos_dt.Add(28, 22);
            qqos_dt.Add(27, 20);
            qqos_dt.Add(26, 18);
            qqos_dt.Add(25, 16);
            qqos_dt.Add(24, 14);
            qqos_dt.Add(23, 12);
            qqos_dt.Add(22, 10);
            qqos_dt.Add(21, 08);
            qqos_dt.Add(20, 06);
            qqos_dt.Add(19, 04);
            qqos_dt.Add(18, 02);

            hqjs_dt.Add(40, 11);
            hqjs_dt.Add(39, 09);
            hqjs_dt.Add(38, 07);
            hqjs_dt.Add(37, 05);
            hqjs_dt.Add(36, 03);
            hqjs_dt.Add(35, 01);


            hqos_dt.Add(46, 12);
            hqos_dt.Add(45, 10);
            hqos_dt.Add(44, 08);
            hqos_dt.Add(43, 06);
            hqos_dt.Add(42, 04);
            hqos_dt.Add(41, 02);
            #endregion


            for (int i = 0; i < arlist.Count; i++)
            {
                //重号
                string[] redBall = arlist[i].LotteryNo.Split('+')[0].Split(',');
                for (int m = 0; m < redBall.Length; m++)
                {
                    //计算条形图中每个数的个数红球
                    bindTiaoxing(0, int.Parse(redBall[m]));

                }

                string[] blueBall = arlist[i].LotteryNo.Split('+')[1].Split(',');
                for (int m = 0; m < blueBall.Length; m++)
                {
                    //计算条形图中每个数的个数红球
                    bindTiaoxing(1, int.Parse(blueBall[m]));

                }
            }
            #region
            foreach (DictionaryEntry de in qqjs_dt)
            {
                int a = int.Parse(de.Value.ToString()) - 1;
                string b = TiaoxingDT[a].ToString();
                qqjs_tiao.Add(de.Key, b);
            }
            foreach (DictionaryEntry de in qqos_dt)
            {
                int a = int.Parse(de.Value.ToString()) - 1;
                string b = TiaoxingDT[a].ToString();
                qqos_tiao.Add(de.Key, b);
            }
            foreach (DictionaryEntry de in hqjs_dt)
            {
                int a = int.Parse(de.Value.ToString()) - 1;
                string b = TiaoxingDT[a].ToString();
                hqjs_tiao.Add(de.Key, b);
            }
            foreach (DictionaryEntry de in hqos_dt)
            {
                int a = int.Parse(de.Value.ToString()) - 1;
                string b = TiaoxingDT[a].ToString();
                hqos_tiao.Add(de.Key, b);
            }
            #endregion
        }



    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        jinqiCount = int.Parse(DropDownList1.SelectedValue);
        bindData(int.Parse(DropDownList1.SelectedValue));
        YiLouZhi1(int.Parse(DropDownList1.SelectedValue));

    }
    protected int[] TiaoxingDT = new int[47];
    protected void bindTiaoxing(int type, int data)
    {
        for (int i = 0; i < 47; i++)
        {
            if (type == 0)
            {
                if (data == (i + 1))
                {
                    TiaoxingDT[i] += 1;
                }
            }
            if (type == 1)
            {
                if (data == (i + 1 - 35))
                {
                    TiaoxingDT[i] += 1;
                }
            }
        }
    }

    #region 遗漏用到的变量   
    protected List<List<List<string>>> ylist_qqjs = new List<List<List<string>>>();
    protected List<List<List<string>>> ylist_qqos = new List<List<List<string>>>();
    protected List<List<List<string>>> ylist_hqjs = new List<List<List<string>>>();
    protected List<List<List<string>>> ylist_hqos = new List<List<List<string>>>();

    #endregion
    public void YiLouZhi1(int maxValue)
    {
        arlist = BLL.LotteryAnnouncement.getDatas(maxValue, 2);
        if (arlist == null || arlist.Count < 0) return;
        List<List<string>> winList = new List<List<string>>();//记录中奖号码和中奖期数，前区红球
        List<List<string>> blue_winList = new List<List<string>>();//后区篮球
        for (int i = 0; i < arlist.Count; i++)
        {

            string lotteryQS = arlist[i].LotteryQS;//开奖期数
            string lotteryNo = arlist[i].LotteryNo;//开奖号码
            string num = "";
            List<List<string>> y_qqjs = new List<List<string>>();
            for (int j = 0; j < qqjs_dt.Count; j++)
            {
                #region 前区奇数
                string[] ball = lotteryNo.Split(new char[] { '+' });
                string redballstr = ball[0];//预测号码中的红球
                string[] redballparm = redballstr.Split(new char[] { ',' });//红球
                if (j < 5)
                {
                    num = "0" + qqjs_dt[j].ToString();
                }
                else
                {
                    num = qqjs_dt[j].ToString();
                }
                string NewQS = "";

                if (i == 0)
                {
                    NewQS = arlist[0].LotteryQS;//当前最新一期
                }
                else
                {
                    for (int m = 0; m < winList.Count; m++)//有命中号码后，将最新一期设为命中的那期
                    {
                        //if ((winList[m][1].Contains(num)))
                        //{
                        //    NewQS = winList[m][0];
                        //}
                        if (winList[m][1] == num.ToString())
                        {
                            if (winList[m][0] == arlist[0].LotteryQS)
                            {
                                NewQS = (int.Parse(arlist[i].LotteryQS) - (i + 1)).ToString();
                            }
                            else
                            {
                                NewQS = winList[m][0];
                            }

                        }

                    }
                    if (NewQS == "")
                    {
                        NewQS = arlist[0].LotteryQS;
                    }
                }
                if (((IList)redballparm).Contains(num))
                {
                    #region 命中值
                    List<string> list = new List<string>();
                    list.Add(lotteryQS);
                    list.Add(num);
                    list.Add("0");
                    y_qqjs.Add(list);
                    List<string> list1 = new List<string>();
                    list1.Add(lotteryQS);
                    list1.Add(num);
                    list1.Add(num);
                    winList.Add(list1);
                    #endregion
                }
                else
                {
                    #region 遗漏值
                    int MissingQS = 0;
                    List<string> list = new List<string>();

                    if (NewQS == arlist[0].LotteryQS)
                    {
                        MissingQS = (Convert.ToInt32(lotteryQS) - Convert.ToInt32(NewQS)) + 1;//遗漏期数
                    }
                    else
                    {
                        for (int m = 0; m < winList.Count; m++)
                        {
                            if (winList[m][1] == num.ToString())
                            {
                                if (winList[m][0] == arlist[0].LotteryQS)
                                {
                                    NewQS = (int.Parse(arlist[i].LotteryQS) - i).ToString();
                                }
                                else
                                {
                                    NewQS = winList[m][0];
                                }

                            }
                        }
                        MissingQS = Convert.ToInt32(lotteryQS) - Convert.ToInt32(NewQS);//遗漏期数
                    }

                    list.Add(lotteryQS);
                    list.Add(qqjs_dt[j].ToString());
                    list.Add(MissingQS.ToString());
                    y_qqjs.Add(list);
                    #endregion
                }
                #endregion
            }
            ylist_qqjs.Add(y_qqjs);


            List<List<string>> y_qqos = new List<List<string>>();
            for (int k = 18; k < qqos_dt.Count + 18; k++)
            {
                #region 前区偶数
                string[] ball = lotteryNo.Split(new char[] { '+' });
                string redballstr = ball[0];//预测号码中的红球
                string[] redballparm = redballstr.Split(new char[] { ',' });//红球
                if (k < 22)
                {
                    num = "0" + qqos_dt[k].ToString();
                }
                else
                {
                    num = qqos_dt[k].ToString();
                }
                string NewQS = "";

                if (i == 0)
                {
                    NewQS = arlist[0].LotteryQS;//当前最新一期
                }
                else
                {
                    for (int m = 0; m < winList.Count; m++)//有命中号码后，将最新一期设为命中的那期
                    {
                        //if ((winList[m][1].Contains(num)))
                        //{
                        //    NewQS = winList[m][0];
                        //}
                        if (winList[m][1] == num.ToString())
                        {
                            if (winList[m][0] == arlist[0].LotteryQS)
                            {
                                NewQS = (int.Parse(arlist[i].LotteryQS) - (i + 1)).ToString();
                            }
                            else
                            {
                                NewQS = winList[m][0];
                            }

                        }
                    }
                    if (NewQS == "")
                    {
                        NewQS = arlist[0].LotteryQS;
                    }
                }
                if (((IList)redballparm).Contains(num))
                {
                    #region 命中值
                    List<string> list = new List<string>();
                    list.Add(lotteryQS);
                    list.Add(num);
                    list.Add("0");
                    y_qqos.Add(list);
                    List<string> list1 = new List<string>();
                    list1.Add(lotteryQS);
                    list1.Add(num);
                    list1.Add(qqos_dt[k].ToString());
                    winList.Add(list1);
                    #endregion
                }
                else
                {
                    #region 遗漏值
                    int MissingQS = 0;
                    List<string> list = new List<string>();

                    if (NewQS == arlist[0].LotteryQS)
                    {
                        MissingQS = (Convert.ToInt32(lotteryQS) - Convert.ToInt32(NewQS)) + 1;//遗漏期数
                    }
                    else
                    {
                        for (int m = 0; m < winList.Count; m++)
                        {
                            if (winList[m][1] == num.ToString())
                            {
                                if (winList[m][0] == arlist[0].LotteryQS)
                                {
                                    NewQS = (int.Parse(arlist[i].LotteryQS) - i).ToString();
                                }
                                else
                                {
                                    NewQS = winList[m][0];
                                }

                            }
                        }
                        MissingQS = Convert.ToInt32(lotteryQS) - Convert.ToInt32(NewQS);//遗漏期数
                    }

                    list.Add(lotteryQS);
                    list.Add(num);
                    list.Add(MissingQS.ToString());
                    y_qqos.Add(list);
                    #endregion
                }
                #endregion
            }
            ylist_qqos.Add(y_qqos);



            List<List<string>> y_hqjs = new List<List<string>>();
            for (int a = 35; a < hqjs_dt.Count + 35; a++)
            {
                #region 后区奇数
                string[] ball = lotteryNo.Split(new char[] { '+' });
                string redballstr = ball[1];//预测号码中的红球
                string[] redballparm = redballstr.Split(new char[] { ',' });//篮球
                if (a < 40)
                {
                    num = "0" + hqjs_dt[a].ToString();
                }
                else
                {
                    num = hqjs_dt[a].ToString();
                }
                string NewQS = "";

                if (i == 0)
                {
                    NewQS = arlist[0].LotteryQS;//当前最新一期
                }
                else
                {
                    for (int m = 0; m < blue_winList.Count; m++)//有命中号码后，将最新一期设为命中的那期
                    {
                        //if ((blue_winList[m][1].Contains(num)))
                        //{
                        //    NewQS = blue_winList[m][0];
                        //}
                        if (blue_winList[m][1] == num.ToString())
                        {
                            if (blue_winList[m][0] == arlist[0].LotteryQS)
                            {
                                NewQS = (int.Parse(arlist[i].LotteryQS) - (i + 1)).ToString();
                            }
                            else
                            {
                                NewQS = blue_winList[m][0];
                            }

                        }
                    }
                    if (NewQS == "")
                    {
                        NewQS = arlist[0].LotteryQS;
                    }
                }
                if (((IList)redballparm).Contains(num))
                {
                    #region 命中值
                    List<string> list = new List<string>();
                    list.Add(lotteryQS);
                    list.Add(num);
                    list.Add("0");
                    y_hqjs.Add(list);
                    List<string> list1 = new List<string>();
                    list1.Add(lotteryQS);
                    list1.Add(num);
                    list1.Add(hqjs_dt[a].ToString());
                    blue_winList.Add(list1);
                    #endregion
                }
                else
                {
                    #region 遗漏值
                    int MissingQS = 0;
                    List<string> list = new List<string>();

                    if (NewQS == arlist[0].LotteryQS)
                    {
                        MissingQS = (Convert.ToInt32(lotteryQS) - Convert.ToInt32(NewQS)) + 1;//遗漏期数
                    }
                    else
                    {
                        for (int m = 0; m < blue_winList.Count; m++)
                        {
                            if (blue_winList[m][1] == num.ToString())
                            {
                                if (blue_winList[m][0] == arlist[0].LotteryQS)
                                {
                                    NewQS = (int.Parse(arlist[i].LotteryQS) - i).ToString();
                                }
                                else
                                {
                                    NewQS = blue_winList[m][0];
                                }

                            }
                        }
                        MissingQS = Convert.ToInt32(lotteryQS) - Convert.ToInt32(NewQS);//遗漏期数
                    }

                    list.Add(lotteryQS);
                    list.Add(num);
                    list.Add(MissingQS.ToString());
                    y_hqjs.Add(list);
                    #endregion
                }
                #endregion
            }
            ylist_hqjs.Add(y_hqjs);

            List<List<string>> y_hqos = new List<List<string>>();
            for (int b = 41; b < hqos_dt.Count + 41; b++)
            {
                #region 后区偶数
                string[] ball = lotteryNo.Split(new char[] { '+' });
                string redballstr = ball[1];//预测号码中的红球
                string[] redballparm = redballstr.Split(new char[] { ',' });//篮球
                if (b < 45)
                {
                    num = "0" + hqos_dt[b].ToString();
                }
                else
                {
                    num = hqos_dt[b].ToString();
                }
                string NewQS = "";

                if (i == 0)
                {
                    NewQS = arlist[0].LotteryQS;//当前最新一期
                }
                else
                {
                    for (int m = 0; m < blue_winList.Count; m++)//有命中号码后，将最新一期设为命中的那期
                    {
                        //if ((blue_winList[m][1].Contains(num)))
                        //{
                        //    NewQS = blue_winList[m][0];
                        //}
                        if (blue_winList[m][1] == num.ToString())
                        {
                            if (blue_winList[m][0] == arlist[0].LotteryQS)
                            {
                                NewQS = (int.Parse(arlist[i].LotteryQS) - (i + 1)).ToString();
                            }
                            else
                            {
                                NewQS = blue_winList[m][0];
                            }

                        }
                    }
                    if (NewQS == "")
                    {
                        NewQS = arlist[0].LotteryQS;
                    }
                }
                if (((IList)redballparm).Contains(num))
                {
                    #region 命中值
                    List<string> list = new List<string>();
                    list.Add(lotteryQS);
                    list.Add(num);
                    list.Add("0");
                    y_hqos.Add(list);
                    List<string> list1 = new List<string>();
                    list1.Add(lotteryQS);
                    list1.Add(num);
                    list1.Add(hqos_dt[b].ToString());
                    blue_winList.Add(list1);
                    #endregion
                }
                else
                {
                    #region 遗漏值
                    int MissingQS = 0;
                    List<string> list = new List<string>();

                    if (NewQS == arlist[0].LotteryQS)
                    {
                        MissingQS = (Convert.ToInt32(lotteryQS) - Convert.ToInt32(NewQS)) + 1;//遗漏期数
                    }
                    else
                    {
                        for (int m = 0; m < blue_winList.Count; m++)
                        {
                            if (blue_winList[m][1] == num.ToString())
                            {
                                if (blue_winList[m][0] == arlist[0].LotteryQS)
                                {
                                    NewQS = (int.Parse(arlist[i].LotteryQS) - i).ToString();
                                }
                                else
                                {
                                    NewQS = blue_winList[m][0];
                                }

                            }
                        }
                        MissingQS = Convert.ToInt32(lotteryQS) - Convert.ToInt32(NewQS);//遗漏期数
                    }

                    list.Add(lotteryQS);
                    list.Add(num);
                    list.Add(MissingQS.ToString());
                    y_hqos.Add(list);
                    #endregion
                }
                #endregion
            }
            ylist_hqos.Add(y_hqos);


        }

    }


}